﻿using System;
using WeixinSDK.API;

namespace WeixinSDK
{
    class Program
    {
        public readonly static NLog.Logger logger = NLog.LogManager.GetLogger(string.Empty);

        static void Main(string[] args)
        {
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Message.ResImage("122"));
            Console.WriteLine(json);
            //TestMediaFile(MediaFile.MediaType.image, @"D:\Program Files (x86)\Microsoft Office\CLIPART\PUB60COR\J0099152.JPG", "d:\\00.jpg");

            Console.ReadKey();
        }

        private static void TestMediaFile(MediaFile.MediaType mediaType, string mediaFile, string downloadFile)
        {
            var token = AccessToken.Get(wxSetting);
            var result = MediaFile.Upload(token, mediaType, mediaFile);

            if (result.media_id != null)
            {
                Console.WriteLine("上传成功");
                logger.Info("上传{0}成功,media_id:{1}", mediaType, result.media_id);

                var err = MediaFile.Download(token, result.media_id, downloadFile);
                if (err != null) Console.WriteLine("下载失败,错误代码:{0},错误信息：{1}", err.errcode, err.errmsg);
            }
            else
            {
                Console.WriteLine("上传失败,错误代码:{0},错误信息：{1}", result.errcode, result.errmsg);
            }
        }

        #region WxSetting

        static WxSetting wxSetting = new WxSetting()
        {
            AppId = "wxc070ee6db2cdc28d",
            AppSecret = "e3a97228c52328f8d2c00bd2f13cce23",
            UserToken = "sjlgolf",
            TokenCacheFolder = AppDomain.CurrentDomain.BaseDirectory
        };

        #endregion
    }
}
